package TAIC.test;

import java.io.File;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Vector;

public class ParaReader {
	public ParaReader ( String filePath ){
		try {
			Scanner scanner = new Scanner ( new File ( filePath)); 
			while ( scanner.hasNext() ) {
				String p1 = scanner.next().trim() ;
				String p2 = scanner.nextLine().trim() ;
				//if ( scanner.hasNextLine () ) scanner.nextLine () ;
				int pos = p2.indexOf( "#") ;
				if ( pos >= 0 ) p2 = p2.substring( 0, pos ).trim() ; 
				paraMap.put( p1.toLowerCase() , p2) ;
			}
			scanner.close();
		} catch ( Exception e ) {
			e.printStackTrace() ; 
		}
	}

	public String getParaStr ( String name ) {
		return paraMap.get( name.toLowerCase() ) ; 
	}
	
	public int getParaInt ( String name ){
		return  Integer.valueOf( paraMap.get(name.toLowerCase() ))  ;
	}
	
	public double getParaDouble ( String name ) {
		return Double.valueOf( paraMap.get(name.toLowerCase() )) ;
	}
	
	public Vector < Integer > getParaIntList ( String name ) {
		String str = paraMap.get( name.toLowerCase() ) ;
		if ( str == null ) return null ; 
		Scanner scanner = new Scanner ( str ) ;
		Vector < Integer > result = new Vector < Integer > () ; 
		while ( scanner.hasNextInt()) result.add( scanner.nextInt() ) ;
		return result; 
	}
	
	private static HashMap < String , String > paraMap = new HashMap < String , String >  () ;
}
